# -*- coding: utf-8 -*-
"""
# @Time    : 2021/1/7 下午3:06
# @Author  : tgy
"""

def test02():
    nums = (x * x for x in range(10))
    for num in nums:
        print(num)

def test01():
    ...
    print("run")
    while True:

        s = yield 1
        if s == 'exit':
            break
        # print(s)
        yield 2


def test03():
    ...

    first = 0
    second = 1
    while True:
        ...
        first, second = second, second+first
        yield first


def fib(n):
    g = test03()
    print(g.__iter__())
    for _ in range(0, n - 1):
        next(g)
    return next(g)

def test04():
    ...
    nums = [x if x % 3 == 0 else -x for x in range(10)]


def my_range(start, end, step=1):
    ...
    cur = start
    if step >= 0:
        while cur < end:
            yield cur
            cur += step
    else:
        while cur > end:
            yield cur
            cur += step


if __name__ == '__main__':
    ...
    # try:
    #     g = test01()
    #     print(next(g))
    #     g.send("exit")
    #     # print(next(g))
    # except StopIteration:
    #     ...
    # print(range(1, 10))
    # print(fib(10))
    for i in my_range(4, 0, -1):
        print(i)
    # for i in range(4,0,-1):
    #     print(i)